package com.central.consume.service.impl;

import com.central.consume.dao.RechargeDAO;
import com.central.consume.model.ChargeDO;
import com.central.consume.model.ChargeLogDO;
import com.central.consume.model.RechargeDetailsVO;
import com.central.consume.service.RechargeService;
import com.central.model.common.PageResult;
import com.central.model.common.utils.PageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Slf4j
@Service
public class RechargeServiceImpl implements RechargeService {

    @Autowired
    private RechargeDAO rechargeDAO;

    @Override
    public PageResult<ChargeDO> listRecharge(Map<String, Object> params) {
        PageUtil.pageParamConver(params, true);
        int total = rechargeDAO.countCharge(params);
        List<ChargeDO> list = Collections.emptyList();
        if (total > 0) {
            list = rechargeDAO.listRechargeInfo(params);
        }
        return PageResult.<ChargeDO>builder().data(list).code(0).count((long) total).build();
    }

    @Override
    public PageResult<RechargeDetailsVO> listRechargeDetails(Map<String, Object> params) {
        PageUtil.pageParamConver(params, true);
        int total = rechargeDAO.countChargeDetails(params);
        List<ChargeLogDO> chargeLogDOList = new ArrayList<>();
        List<RechargeDetailsVO> rechargeDetailsVOList = new ArrayList<>();
        if (total > 0) {
            chargeLogDOList = rechargeDAO.listRechargeDetailsInfo(params);
        }
        chargeLogDOList.forEach(chargeLogDO -> {
            RechargeDetailsVO rechargeDetailsVO = new RechargeDetailsVO(chargeLogDO);
            rechargeDetailsVOList.add(rechargeDetailsVO);
        });
        return PageResult.<RechargeDetailsVO>builder().data(rechargeDetailsVOList).code(0).count((long) total).build();
    }

    /*public static void main(String[] args) {
        List<ChargeLogDO> chargeLogDOList = new ArrayList<>();
        ChargeLogDO chargeLogDO = new ChargeLogDO();
        chargeLogDO.setCreatedAt(new Date());
        chargeLogDO.setFirst(true);
        chargeLogDO.setId(10000L);
        chargeLogDO.setIp("127.0.0.1");
        chargeLogDO.setMoney(20000D);
        chargeLogDO.setOrderId(346546136546843643L);
        chargeLogDO.setTarget(123456789L);
        chargeLogDOList.add(chargeLogDO);
        List<RechargeDetailsVO> rechargeDetailsVOList = Collections.emptyList();
        chargeLogDOList.forEach(chargeLogDO1 -> {
            RechargeDetailsVO rechargeDetailsVO = new RechargeDetailsVO(chargeLogDO1);
            rechargeDetailsVOList.add(rechargeDetailsVO);
        });
        rechargeDetailsVOList.forEach(rechargeDetailsVO -> System.out.println(rechargeDetailsVO));
    }*/
}
